﻿/**
 * Peter
 * Created by: Peter Development Team
 *    http://peter.codeplex.com/
 * 
 * GNU General Public License version 2 (GPLv2)
 *    http://peter.codeplex.com/license
 *
 *  This code is provided on an AS IS basis, with no WARRANTIES,
 *  CONDITIONS or GUARANTEES of any kind.
 *
 **/

using System.Collections.Generic;
using System.Threading.Tasks;
using ICSharpCode.AvalonEdit;
using ICSharpCode.AvalonEdit.CodeCompletion;
using ICSharpCode.AvalonEdit.Document;

namespace Peter.Common.Code
{
   /// <summary>
   /// The base class for code completion.
   /// </summary>
   public abstract class BaseCodeCompletion
   {
      /// <summary>
      /// Gets the completion results for the given document.
      /// </summary>
      /// <param name="document">The document to get completion Results for.</param>
      /// <param name="offset">The offset of the caret.</param>
      /// <param name="controlSpace">True if completion is requested via Ctrl+Space, otherwise false.</param>
      /// <returns>The code completion result.</returns>
      public abstract Task<CodeCompletionResult> GetCompletions (IDocument document, int offset, bool controlSpace);

      /*/// <summary>
      /// Gets the project content.
      /// </summary>
      public IProjectContent ProjectContent { get; protected set; }

      /// <summary>
      /// Adds an assembly for code completion to be aware of.
      /// </summary>
      /// <param name="file">Path to assembly.</param>
      public void AddAssembly (string file)
      {
         if (string.IsNullOrEmpty (file))
            return;

         var loader = new CecilLoader { DocumentationProvider = GetXmlDocumentation (file) };
         var unresolvedAssembly = loader.LoadAssemblyFile (file);
         this.ProjectContent = this.ProjectContent.AddAssemblyReferences (unresolvedAssembly);
      }

      /// <summary>
      /// Adds an assembly for code completion to be aware of.
      /// </summary>
      /// <param name="files">A list of files to add.</param>
      public void AddFiles (IEnumerable <IUnresolvedFile> files)
      {
         this.ProjectContent = this.ProjectContent.AddOrUpdateFiles(files);
      }

      /// <summary>
      /// Updates the file in the code completion code base.
      /// </summary>
      /// <param name="pathToFile">Full path to file to update.</param>
      public abstract void UpdateFile (string pathToFile);

      /// <summary>
      /// Gets the xml documentation for the given dll.
      /// </summary>
      /// <param name="dllPath">Path to dll to get xml documentation for.</param>
      /// <returns>XmlDocumentationProvider</returns>
      protected abstract XmlDocumentationProvider GetXmlDocumentation (string dllPath);

      /// <summary>
      /// Attempts to show the code completion window.
      /// </summary>
      /// <param name="enteredText">The text that was entered.</param>
      /// <param name="completionWindow">The completion window from avalon edit.</param>
      /// <param name="insightWindow">The insight window from avalon edit.</param>
      /// <param name="editor">The text editor.</param>
      public abstract Task ShowCompletion (string enteredText, CompletionWindow completionWindow,
         OverloadInsightWindow insightWindow, TextEditor editor);

      /// <summary>
      /// Checks if the given extension is supported by this completion item.
      /// </summary>
      /// <param name="extension">Extension to check.</param>
      /// <returns>True if supported otherwise false.</returns>
      public abstract bool Supports (string extension);*/
   }
}
